package cn.stylefeng.guns.modular.agv.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.agv.entity.AgvStorageTaskList;
import cn.stylefeng.guns.modular.agv.model.params.AgvStorageTaskListParam;
import cn.stylefeng.guns.modular.agv.service.AgvStorageTaskListService;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * agv拣选任务下发列表控制器
 *
 * @author zhangzh
 * @Date 2025-07-08 17:06:55
 */
@Controller
@RequestMapping("/agvStorageTaskList")
public class AgvStorageTaskListController extends BaseController {

    private String PREFIX = "/agv/agvStorageTaskList";

    @Autowired
    private AgvStorageTaskListService agvStorageTaskListService;

    @Autowired
    private UserService userService;

    @Autowired
    private BasicWarehouseService basicWarehouseService;

    /**
     * 跳转到主页面
     *
     * @author zhangzh
     * @Date 2025-07-08
     */
    @RequestMapping("")
    public String index(Model model) {
        User user = userService.getcurrentUser();
        Long deptId = user.getDeptId();
        Long deliverId = user.getDeliverId();
        //查询可选择仓库
        model.addAttribute("basicWarehouseList", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/agvStorageTaskList.html";
    }

    /**
     * 新增页面
     *
     * @author zhangzh
     * @Date 2025-07-08
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/agvStorageTaskList_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zhangzh
     * @Date 2025-07-08
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/agvStorageTaskList_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zhangzh
     * @Date 2025-07-08
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(AgvStorageTaskListParam agvStorageTaskListParam) {
        this.agvStorageTaskListService.add(agvStorageTaskListParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zhangzh
     * @Date 2025-07-08
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(AgvStorageTaskListParam agvStorageTaskListParam) {
        this.agvStorageTaskListService.update(agvStorageTaskListParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhangzh
     * @Date 2025-07-08
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(AgvStorageTaskListParam agvStorageTaskListParam) {
        this.agvStorageTaskListService.delete(agvStorageTaskListParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zhangzh
     * @Date 2025-07-08
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(AgvStorageTaskListParam agvStorageTaskListParam) {
        AgvStorageTaskList detail = this.agvStorageTaskListService.getById(agvStorageTaskListParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zhangzh
     * @Date 2025-07-08
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(AgvStorageTaskListParam agvStorageTaskListParam,String condition ) {
        User user = userService.getcurrentUser();
        agvStorageTaskListParam.setDeptId(user.getDeptId());
        return this.agvStorageTaskListService.findPageBySpec(agvStorageTaskListParam,condition);
    }

}


